package day4;


import java.util.Scanner;

//进制转换
public class oj2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int m = scan.nextInt();
        int n = scan.nextInt();
        StringBuilder s = new StringBuilder();
        String table = "0123456789ABCDEF";
        boolean flg = false;
        //m 等于0则输出0
        if(m == 0) {
            System.out.println(0);
        }
        //如果m等于负数 先变为正数
        if(m < 0 ) {
            m = -m;
            flg = true;
        }
        //每次%n 的数拼接在后面，再/n
        while(m != 0) {
            s.append(table.charAt(m % n));
            m = m / n;
        }
        //如果为负数就拼接一个-
        if(flg) {
            s.append("-");
        }
        //翻转
        s.reverse();
        System.out.println(s);
    }
}
